5 http://daringfireball.net/
7 Version 1.5.1 - Fri 12 Mar 2004
10 SmartyPants is a free web publishing plug-in for Movable Type, Blosxom,
11 and BBEdit that easily translates plain ASCII punctuation characters
12 into "smart" typographic punctuation HTML entities. SmartyPants can also
13 be invoked as a standalone Perl script.
15 SmartyPants can perform the following transformations:
17 * Straight quotes (`"` and `'`) into "curly" quote HTML entities
19 * Backtick-style quotes (` ``like this'' `) into "curly" quote HTML
22 * Dashes (`--` and `---`) into en- and em-dash entities
24 * Three consecutive dots (`...`) into an ellipsis entity
26 This means you can write, edit, and save your posts using plain old
27 ASCII straight quotes, plain dashes, and plain dots, but your published
28 posts (and final HTML output) will appear with smart quotes, em-dashes,
31 SmartyPants is a combination plug-in -- the same file works with Movable
32 Type, Blosxom, and BBEdit. It can also be used from a Unix-style
33 command-line. Version requirements and installation instructions for
34 each of these tools can be found in the corresponding sub-section under
35 "Installation", below.
37 SmartyPants does not modify characters within `<pre>`, `<code>`,
38 `<kbd>`, or `<script>` tag blocks. Typically, these tags are used to
39 display text where smart quotes and other "smart punctuation" would not
40 be appropriate, such as source code or example markup.
43 ### Backslash Escapes ###
45 If you need to use literal straight quotes (or plain hyphens and
46 periods), SmartyPants accepts the following backslash escape sequences
47 to force non-smart punctuation. It does so by transforming the escape
48 sequence into a decimal-encoded HTML entity:
51 Escape Value Character
52 ------ ----- ---------
61 This is useful, for example, when you want to use straight quotes as
70 in SmartyPants's HTML output. Which, when rendered by a web browser,
76 ### Markdown and MT-Textile Integration ###
78 Movable Type users should also note that SmartyPants can be used in
79 conjunction with two text filtering plug-ins: [Markdown] [1] and Brad
80 Choate's [MT-Textile] [2].
82 [1]: http://daringfireball.net/projects/markdown/
83 [2]: http://www.bradchoate.com/mt-plugins/textile
85 Markdown is my text-to-HTML filter, and is intended to be an
86 easy-to-write and easy-to-read structured text format for writing for
87 the web. You write plain text; Markdown turns it into HTML. This readme
88 file is formatted in Markdown.
90 When Markdown and SmartyPants are both present in the same Movable Type
91 installation, the "Markdown With SmartyPants" filter will be available
92 from MT's Text Formatting pop-up menu. The "Markdown With SmartyPants"
93 filter automatically applies SmartyPants to the bodies of your entries;
94 the regular "Markdown" filter does not. See the Markdown web page for
97 MT-Textile is a port of Dean Allen's original [Textile] [3] project to
98 Perl and Movable Type. MT-Textile by itself only translates Textile
99 markup to HTML. However, if SmartyPants is also installed, MT-Textile
100 will call on SmartyPants to educate quotes, dashes, and ellipses,
101 automatically. Textile is Dean Allen's "humane web text generator",
102 another easy-to-write and easy-to-read shorthand for web writing. An
103 [online Textile web application] [3] is available at Mr. Allen's site.
105 [3]: http://textism.com/tools/textile/
107 Using SmartyPants in conjunction with MT-Textile or the "Markdown With
108 SmartyPants" filter requires no modifications to your Movable Type
109 templates. You simply choose the appropriate filter from the Text
110 Formatting menu, on a per-post basis. However, note that as of this
111 writing, Movable Type does not apply text filters to article titles or
112 excerpts; you'll need to edit your templates to get SmartyPants
113 processing for those fields.
115 You'll also need to invoke SmartyPants from your templates if you want
116 to use non-default settings, such as en-dash support. For explicit
117 control, I recommend using the regular "Markdown" text filter, and
118 invoking SmartyPants from your templates.
126 SmartyPants works with Movable Type version 2.5 or later.
128 1. Copy the "SmartyPants.pl" file into your Movable Type "plugins"
129 directory. The "plugins" directory should be in the same directory
130 as "mt.cgi"; if it doesn't already exist, use your FTP program to
131 create it. Your installation should look like this:
133 (mt home)/plugins/SmartyPants.pl
135 2. If you're using SmartyPants with Markdown or MT-Textile, you're
138 If not, or if you want explicit control over SmartyPants's behavior,
139 you need to edit your MT templates. The easiest way is to add the
140 "smarty_pants" attribute to each MT template tag whose contents you
141 wish to apply SmartyPants's transformations. Obvious tags would
142 include `MTEntryTitle`, `MTEntryBody`, and `MTEntryMore`.
143 SmartyPants should work within any MT content tag.
145 For example, to apply SmartyPants to your entry titles:
147 <$MTEntryTitle smarty_pants="1"$>
149 The value passed to the `smarty_pants` attribute specifies the way
150 SmartyPants works. See "Options", below, for full details on all of
151 the supported options.
156 SmartyPants works with Blosxom version 2.0 or later.
158 1. Rename the "SmartyPants.pl" plug-in to "SmartyPants" (case is
159 important). Movable Type requires plug-ins to have a ".pl"
160 extension; Blosxom forbids it (at least as of this writing).
162 2. Copy the "SmartyPants" plug-in file to your Blosxom plug-ins folder.
163 If you're not sure where your Blosxom plug-ins folder is, see the
164 Blosxom documentation for information.
166 3. That's it. The entries in your weblog should now automatically have
167 SmartyPants's default transformations applied.
169 4. If you wish to configure SmartyPants's behavior, open the
170 "SmartyPants" plug-in, and edit the value of the `$smartypants_attr`
171 configuration variable, located near the top of the script. The
172 default value is 1; see "Options", below, for the full list of
178 SmartyPants works with BBEdit 6.1 or later on Mac OS X; and BBEdit 5.1
179 or later on Mac OS 9 or earlier (provided you have MacPerl installed).
181 1. Copy the "SmartyPants.pl" file to appropriate filters folder in your
182 "BBEdit Support" folder. On Mac OS X, this should be:
184 BBEdit Support/Unix Support/Unix Filters/
186 On Mac OS 9 or earlier, this should be:
188 BBEdit Support:MacPerl Support:Perl Filters:
190 See the BBEdit documentation for more details on the location of
193 You can rename "SmartyPants.pl" to whatever you wish.
195 2. That's it. To use SmartyPants, select some text in a BBEdit
196 document, then choose SmartyPants from the Filters sub-menu or the
197 Filters floating palette. On Mac OS 9, the Filters sub-menu is in
198 the "Camel" menu; on Mac OS X, it is in the "#!" menu.
200 3. If you wish to configure SmartyPants's behavior, open the SmartyPants
201 file and edit the value of the `$smartypants_attr` configuration
202 variable, located near the top of the script. The default value is
203 1; see "Options", below, for the full list of supported values.
208 SmartyPants works as a standalone Perl script. You can invoke it from a
209 Unix-style command line, passing input as a file argument or as piped
210 input via STDIN. See the POD documentation for information on the
211 command-line switches SmartyPants accepts.
214 Options and Configuration
215 -------------------------
217 For MT users, the `smarty_pants` template tag attribute is where you
218 specify configuration options. For Blosxom and BBEdit users, settings
219 are specified by editing the value of the `$smartypants_attr` variable in
222 Numeric values are the easiest way to configure SmartyPants's behavior:
225 Suppress all transformations. (Do nothing.)
228 Performs default SmartyPants transformations: quotes (including
229 backticks-style), em-dashes, and ellipses. `--` (dash dash) is
230 used to signify an em-dash; there is no support for en-dashes.
233 Same as smarty_pants="1", except that it uses the old-school
234 typewriter shorthand for dashes: `--` (dash dash) for en-dashes,
235 `---` (dash dash dash) for em-dashes.
238 Same as smarty_pants="2", but inverts the shorthand for dashes: `--`
239 (dash dash) for em-dashes, and `---` (dash dash dash) for en-dashes.
242 Stupefy mode. Reverses the SmartyPants transformation process,
243 turning the HTML entities produced by SmartyPants into their ASCII
244 equivalents. E.g. `“` is turned into a simple double-quote
245 (`"`), `—` is turned into two dashes, etc. This is useful if you
246 are using SmartyPants from Brad Choate's MT-Textile text filter, but
247 wish to suppress smart punctuation in specific MT templates, such as
248 RSS feeds. Text filters do their work before templates are
249 processed; but you can use smarty_pants="-1" to reverse the
250 transformations in specific templates.
252 The following single-character attribute values can be combined to
253 toggle individual transformations from within the smarty_pants
254 attribute. For example, to educate normal quotes and em-dashes, but not
255 ellipses or backticks-style quotes:
257 <$MTFoo smarty_pants="qd"$>
260 Educates normal quote characters: (`"`) and (`'`).
263 Educates ` ``backticks'' ` double quotes.
266 Educates backticks-style double quotes and ` `single' ` quotes.
272 Educates em-dashes and en-dashes, using old-school typewriter
273 shorthand: (dash dash) for en-dashes, (dash dash dash) for
277 Educates em-dashes and en-dashes, using inverted old-school
278 typewriter shorthand: (dash dash) for em-dashes, (dash dash dash)
285 Translates any instance of `"` into a normal double-quote
286 character. This should be of no interest to most people, but of
287 particular interest to anyone who writes their posts using
288 Dreamweaver, as Dreamweaver inexplicably uses this entity to
289 represent a literal double-quote character. SmartyPants only
290 educates normal quotes, not entities (because ordinarily, entities
291 are used for the explicit purpose of representing the specific
292 character they represent). The "w" option must be used in
293 conjunction with one (or both) of the other quote options ("q" or
294 "b"). Thus, if you wish to apply all SmartyPants transformations
295 (quotes, en- and em-dashes, and ellipses) and also translate
296 `"` entities into regular quotes so SmartyPants can educate
297 them, you should pass the following to the smarty_pants attribute:
299 <$MTFoo smarty_pants="qDew"$>
301 For Blosxom and BBEdit users, set:
303 my $smartypants_attr = "qDew";
306 ### Deprecated MT Attributes ###
308 Older versions of SmartyPants supplied optional `smart_quotes`,
309 `smart_dashes`, and `smart_ellipses` MT template attributes. These
310 attributes are now officially deprecated.
313 ### Version Info Tag ###
315 If you include this tag in a Movable Type template:
317 <$MTSmartyPantsVersion$>
319 it will be replaced with a string representing the version number of the
320 installed version of SmartyPants, e.g. "1.5".
326 ### Why You Might Not Want to Use Smart Quotes in Your Weblog ###
328 For one thing, you might not care.
330 Most normal, mentally stable individuals do not take notice of proper
331 typographic punctuation. Many design and typography nerds, however,
332 break out in a nasty rash when they encounter, say, a restaurant sign
333 that uses a straight apostrophe to spell "Joe's".
335 If you're the sort of person who just doesn't care, you might well want
336 to continue not caring. Using straight quotes -- and sticking to the
337 7-bit ASCII character set in general -- is certainly a simpler way to
340 Even if you *do* care about accurate typography, you still might want to
341 think twice before educating the quote characters in your weblog. One
342 side effect of publishing curly quote HTML entities is that it makes
343 your weblog a bit harder for others to quote from using copy-and-paste.
344 What happens is that when someone copies text from your blog, the copied
345 text contains the 8-bit curly quote characters (as well as the 8-bit
346 characters for em-dashes and ellipses, if you use these options). These
347 characters are not standard across different text encoding methods,
348 which is why they need to be encoded as HTML entities.
350 People copying text from your weblog, however, may not notice that
351 you're using curly quotes, and they'll go ahead and paste the unencoded
352 8-bit characters copied from their browser into an email message or
353 their own weblog. When pasted as raw "smart quotes", these characters
354 are likely to get mangled beyond recognition.
356 That said, my own opinion is that any decent text editor or email client
357 makes it easy to stupefy smart quote characters into their 7-bit
358 equivalents, and I don't consider it my problem if you're using an
359 indecent text editor or email client.
361 ### Algorithmic Shortcomings ###
363 One situation in which quotes will get curled the wrong way is when
364 apostrophes are used at the start of leading contractions. For example:
366 'Twas the night before Christmas.
368 In the case above, SmartyPants will turn the apostrophe into an opening
369 single-quote, when in fact it should be a closing one. I don't think
370 this problem can be solved in the general case -- every word processor
371 I've tried gets this wrong as well. In such cases, it's best to use the
372 proper HTML entity for closing single-quotes (`’` or `’`) by
379 To file bug reports or feature requests (other than topics listed in the
380 Caveats section above) please send email to:
382 smartypants@daringfireball.net
384 If the bug involves quotes being curled the wrong way, please send
385 example text to illustrate.
391 1.5.1: Fri 12 Mar 2004
393 * Fixed a goof where if you had SmartyPants 1.5.0 installed,
394 but didn't have Markdown installed, when SmartyPants checked
395 for Markdown's presence, it created a blank entry in MT's
396 global hash of installed text filters. This showed up in MT's
397 Text Formatting pop-up menu as a blank entry.
402 * Integration with Markdown. If Markdown is already loaded
403 when SmartyPants loads, SmartyPants will add a new global
404 text filter, "Markdown With Smartypants".
406 * Preliminary command-line options parsing. -1 -2 -3
409 * dot-space-dot-space-dot now counts as an ellipsis.
410 This is the style used by Project Gutenberg:
411 http://www.gutenberg.net/faq/index.shtml#V.110
412 (Thanks to Fred Condo for the patch.)
414 * Added `<math>` to the list of tags to skip (pre, code, etc.).
417 1.4.1: Sat 8 Nov 2003
419 * The bug fix from 1.4 for dashes followed by quotes with no
420 intervening spaces now actually works.
422 * ` ` now counts as whitespace where necessary. (Thanks to
423 Greg Knauss for the patch.)
428 * Improved the HTML tokenizer so that it will parse nested <> pairs
429 up to five levels deep. Previously, it only parsed up to two
430 levels. What we *should* do is allow for any arbitrary level of
431 nesting, but to do so, we would need to use Perl's `??` construct
432 (see Fried's "Mastering Regular Expressions", 2nd Ed., pp.
433 328-331), and sadly, this would only work in Perl 5.6 or later.
434 SmartyPants still supports Perl 5.00503. I suppose we could test
435 for the version and build a regex accordingly, but I don't think
436 I want to maintain two separate patterns.
438 * Thanks to Stepan Riha, the tokenizer now handles HTML comments:
442 and PHP-style processor instructions:
446 * The quote educator now handles situations where dashes are used
447 without whitespace, e.g.:
449 "dashes"--without spaces--"are tricky"
451 * Special case for decade abbreviations like this: `the '80s`.
452 This only works for the sequence appostrophe-digit-digit-s.
457 * Plugged the biggest hole in SmartyPants's smart quotes algorithm.
458 Previous versions were hopelessly confused by single-character
459 quote tokens, such as:
461 <p>"<i>Tricky!</i>"</p>
463 The problem was that the EducateQuotes() function works on each
464 token separately, with no means of getting surrounding context
465 from the previous or next tokens. The solution is to curl these
466 single-character quote tokens as a special case, *before* calling
469 * New single-quotes backtick mode for smarty_pants attribute.
470 The only way to turn it on is to include "B" in the configuration
471 string, e.g. to translate backtick quotes, dashes, and ellipses:
475 * Fixed a bug where an opening quote would get curled the wrong way
476 if the quote started with three dots, e.g.:
478 <p>"...meanwhile"</p>
480 * Fixed a bug where opening quotes would get curled the wrong way
481 if there were double sets of quotes within each other, e.g.:
483 <p>"'Some' people."</p>
485 * Due to popular demand, four consecutive dots (....) will now be
486 turned into an ellipsis followed by a period. Previous versions
487 would turn this into a period followed by an ellipsis. If you
488 really want a period-then-ellipsis sequence, escape the first
489 period with a backslash: \....
491 * Removed `&` from our home-grown punctuation class, since it
492 denotes an entity, not a literal ampersand punctuation
493 character. This fixes a bug where SmartyPants would mis-curl
494 the opening quote in something like this:
498 * SmartyPants has always had a special case where it looks for
499 "'s" in situations like this:
501 <i>Custer</i>'s Last Stand
503 This special case is now case-insensitive.
506 1.2.2: Thu Mar 13, 2003
508 * 1.2.1 contained a boneheaded addition which prevented SmartyPants
509 from compiling under Perl 5.005. This has been remedied, and is
510 the only change from 1.2.1.
513 1.2.1: Mon Mar 10, 2003
515 * New "stupefy mode" for smarty_pants attribute. If you set
519 SmartyPants will perform reverse transformations, turning HTML
520 entities into plain ASCII equivalents. E.g. "“" is turned
521 into a simple double-quote ("), "—" is turned into two
522 dashes, etc. This is useful if you are using SmartyPants from Brad
523 Choate's MT-Textile text filter, but wish to suppress smart
524 punctuation in specific MT templates, such as RSS feeds. Text
525 filters do their work before templates are processed; but you can
526 use smarty_pants="-1" to reverse the transformations in specific
529 * Replaced the POSIX-style regex character class `[:punct:]` with an
530 ugly hard-coded normal character class of all punctuation; POSIX
531 classes require Perl 5.6 or later, but SmartyPants still supports
534 * Several small changes to allow SmartyPants to work when Blosxom
535 is running in static mode.
538 1.2: Thu Feb 27, 2003
540 * SmartyPants is now a combination plug-in, supporting both
541 Movable Type (2.5 or later) and Blosxom (2.0 or later).
542 It also works as a BBEdit text filter and standalone
543 command-line Perl program. Thanks to Rael Dornfest for the
544 initial Blosxom port (and for the excellent Blosxom plug-in
547 * SmartyPants now accepts the following backslash escapes,
548 to force non-smart punctuation. It does so by transforming
549 the escape sequence into a decimal-encoded HTML entity:
551 Escape Value Character
552 ------ ----- ---------
560 Note that this could produce different results than previous
561 versions of SmartyPants, if for some reason you have an article
562 containing one or more of these sequences. (Thanks to Charles
563 Wiltgen for the suggestion.)
565 * Added a new option to support inverted en- and em-dash notation:
566 `--` for em-dashes, `---` for en-dashes. This is compatible with
567 SmartyPants's original `--` syntax for em-dashes, but also allows
568 you to specify en-dashes. It can be invoked by using
569 smart_dashes="3", smarty_pants="3", or smarty_pants="i".
570 (Suggested by Aaron Swartz.)
572 * Added a new option to automatically convert `"` entities into
573 regular double-quotes before sending text to EducateQuotes() for
574 processing. This is mainly for the benefit of people who write
575 posts using Dreamweaver, which substitutes this entity for any
576 literal quote char. The one and only way to invoke this option
577 is to use the letter shortcuts for the smarty_pants attribute;
578 the shortcut for this option is "w" (for Dream_w_eaver).
579 (Suggested by Jonathon Delacour.)
581 * Added `<script>` to the list of tags in which SmartyPants doesn't
584 * Fixed a very subtle bug that would occur if a quote was the very
585 last character in a body of text, preceded immediately by a tag.
586 Lacking any context, previous versions of SmartyPants would turn
587 this into an opening quote mark. It's now correctly turned into
590 * Opening quotes were being curled the wrong way when the
591 subsequent character was punctuation. E.g.: "a '.foo' file".
594 * New MT global template tag: `<$MTSmartyPantsVersion$>`
595 Prints the version number of SmartyPants, e.g. "1.2".
600 * The smart_dashes template attribute now offers an option to
601 use `--` for *en* dashes, and `---` for *em* dashes.
603 * The default smart_dashes behavior now simply translates `--`
604 (dash dash) into an em-dash. Previously, it would look for
605 ` -- ` (space dash dash space), which was dumb, since many
606 people do not use spaces around their em dashes.
608 * Using the smarty_pants attribute with a value of "2" will
609 do the same thing as smarty_pants="1", with one difference:
610 it will use the new shortcuts for en- and em-dashes.
612 * Closing quotes (single and double) were incorrectly curled in
613 situations like this:
617 where the comma could be just about any punctuation character.
620 * Added `<kbd>` to the list of tags in which text shouldn't be
624 1.0: Wed Nov 13, 2002
633 http://daringfireball.net
639 Portions of this plug-in are based on Brad Choate's nifty MTRegex
640 plug-in. Brad Choate also contributed a few bits of source code to this
641 plug-in. Brad Choate is a fine hacker indeed. (http://bradchoate.com/)
643 Jeremy Hedley (http://antipixel.com/) and Charles Wiltgen
644 (http://playbacktime.com/) deserve mention for exemplary beta testing.
646 Rael Dornfest (http://raelity.org/) ported SmartyPants to Blosxom.
649 Copyright and License
650 ---------------------
652 Copyright (c) 2004 John Gruber
653 (http://daringfireball.net/)
656 Redistribution and use in source and binary forms, with or without
657 modification, are permitted provided that the following conditions are
660 * Redistributions of source code must retain the above copyright notice,
661 this list of conditions and the following disclaimer.
663 * Redistributions in binary form must reproduce the above copyright
664 notice, this list of conditions and the following disclaimer in the
665 documentation and/or other materials provided with the distribution.
667 * Neither the name "SmartyPants" nor the names of its contributors may
668 be used to endorse or promote products derived from this software
669 without specific prior written permission.
671 This software is provided by the copyright holders and contributors "as
672 is" and any express or implied warranties, including, but not limited
673 to, the implied warranties of merchantability and fitness for a
674 particular purpose are disclaimed. In no event shall the copyright owner
675 or contributors be liable for any direct, indirect, incidental, special,
676 exemplary, or consequential damages (including, but not limited to,
677 procurement of substitute goods or services; loss of use, data, or
678 profits; or business interruption) however caused and on any theory of
679 liability, whether in contract, strict liability, or tort (including
680 negligence or otherwise) arising in any way out of the use of this
681 software, even if advised of the possibility of such damage.